package com.chenyue.cm.api.homePage;

import com.chenyue.cm.bean.Success;
import com.chenyue.cm.common.domain.JdBanner;
import com.chenyue.cm.common.service.CommonInfoService;
import com.chenyue.cm.common.service.JdBannerService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: ljy
 * @Title: BannerController
 * @Description:
 * @Date: 2021-07-26
 */
@Api(value = "banner图api", tags = "banner图api")
@ApiSort(1)
@RestController
@RequestMapping("/api/banner")
public class BannerController {

    private final JdBannerService jdBannerService;

    private final CommonInfoService commonInfoService;

    public BannerController(JdBannerService jdBannerService, CommonInfoService commonInfoService) {
        this.jdBannerService = jdBannerService;
        this.commonInfoService = commonInfoService;
    }

    /**
     * 根据不同城市的code展示不同的banner图
     *
     * @param cityCode 城市code
     * @return Success
     */
    @PostMapping("/getCityBanner")
    @ApiOperation(value = "banner图", notes = "banner图")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "城市编码", name = "cityCode", dataType = "Integer", required = true),
    })
    public Success<List<JdBanner>> getCityBanner(Integer cityCode) {
        final Integer city = commonInfoService.getCity(cityCode);
        List<JdBanner> banner = jdBannerService.getCityBanner(city);
        return Success.success(banner);
    }

    /**
     * 获取引导页
     *
     * @return Success
     */
    @GetMapping("/getGuidePage")
    @ApiOperation(value = "引导页", notes = "引导页")
    @ApiOperationSupport(order = 2)
    public Success<List<JdBanner>> getGuidePage() {
        List<JdBanner> guidePage = jdBannerService.getGuidePage();
        return Success.success(guidePage);
    }

    /**
     * 获取启动页
     *
     * @return Success
     */
    @GetMapping("/getStartPage")
    @ApiOperation(value = "启动页", notes = "启动页")
    @ApiOperationSupport(order = 3)
    public Success<List<JdBanner>> getStartPage() {
        List<JdBanner> startPage = jdBannerService.getStartPage();
        return Success.success(startPage);
    }
}
